<?php
    
    include_once 'islogin.php';
    include_once 'fun.php';
    $name = isset($_GET['Name'])?trim($_GET['Name']):'';
    $category = isset($_GET['category'])?trim($_GET['category']):'';
    $order = isset($_GET['order'])?trim($_GET['order']):'';
   // var_dump($name);
   if($order==''){
       $orderby='Name';
       $order='ASC';
   }
   else {
    $orderby='price';
    if($order==1)
    $order='ASC';
    else
    $order='desc';
   }
   
    if($name&&$category){
        
    $sql = "select * from product where Name like '%$name%'  and  counternum!=0 and category like '%$category%' order by  $orderby $order ";
    
    }
    else if($name)
    {
    $sql = "select * from product where Name like '%$name%'  and  counternum!=0 order by $orderby $order ";
    }
    else if($category)
    $sql = "select * from product where  category like '%$category%' and  counternum!=0  order by  $orderby $order ";
    else
    $sql = "select * from product where counternum!=0 order by  $orderby $order";
    $con=connect();
    $res = query($sql,$con);
    if($res->num_rows==0) 
    $result=array();
    else
    while($row = mysqli_fetch_all($res)){
    $result=$row;

    }
    include_once 'html/index.html';


  

?>